#自定义过滤器
from flask import current_app
from flask import g
from flask import session

from info.models import User


def index_class(index):
    if index == 1:
        return 'first'
    elif index == 2:
        return 'second'
    elif index == 3:
        return 'third'
    else:
        return ''


def login_required(f):
    def wrapper(*args,**kwargs):
        user_id = session.get('user_id')
        user=None
        if user_id:
            # 查询mysql获取用户信息
            try:
                user = User.query.get(user_id)
            except Exception as e:
                current_app.logger.error(e)
        g.user=user
        return  f(*args,**kwargs)
    wrapper.__name__=f.__name__
    return wrapper